<?php
set_time_limit(0);

include "QueryList.php";
include "phpQuery.php";
use QL\QueryList;
$url=curl('http://dianying.114la.com/?kz');
//echo 1;die;
//echo $url;
$rules=[
    'movie_name'=>['.td>h2','text'],
    'movie_jj'=>['.td>p','text'],
    'movie_score'=>['div>div.lpart>div>ul>li>a>span>b','text'],

];
$data=QueryList::Query($url,$rules)->data;
//print_r($data);die;
foreach($data as $key=>$v)
{
    $movie_name=$v['movie_name'];
    $movie_jj=$v['movie_jj'];
    $movie_score=$v['movie_score'];
    $dbh=new PDO('mysql:host=localhost;dbname=gaofei','root','root');
    $sql="insert into happy2 (movie_name,movie_jj,movie_score) VALUE('$movie_name','$movie_jj','$movie_score')";
    $dbh->exec($sql);
}
//$str=curl('http://v.114la.com/movie/40088430.html');
//$preg='#给19岁的我自己.*同类型电影推荐#isU';
//preg_match_all($preg,$str,$arr);
////print_r($arr);die;
//$prega_arr='# <div class=".*">.*<div class=".*">.*</div>.*<ul class=".*">.*<li class="sin">导演：<a href=".*" title=".*" target="_blank">(.*)</a></li>.*<li class=".*">主演：<a href=".*" title=".*" target="_blank">(.*)</a> .*</li>.*<li class=".*">类型：<a class=".*" href=".*">(.*)</a></li>.*<li>国家/地区：(.*)</li>.*<li>年代：(.*)</li>.*</ul>.*<p class=".*" id="intro">简介： (.*)</p>.*</div>#isU';
//preg_match_all($prega_arr,$arr[0][0],$arr_tt);
////print_r($arr_tt);die;
//foreach($arr_tt[1] as $key=>$value)
//{
//    $arr_hh['movie_director']=$arr_tt[1][$key];
//    $arr_hh['movie_zhuyan']=$arr_tt[2][$key];
//    $arr_hh['movie_type']=$arr_tt[3][$key];
//    $arr_hh['movie_area']=$arr_tt[4][$key];
//    $arr_hh['movie_time']=$arr_tt[5][$key];
//    $arr_hh['movie_jj']=$arr_tt[6][$key];
//    $dbh=new PDO('mysql:host=localhost;dbname=gaofei','root','root');
//    $sql="insert into happy(movie_director,movie_zhuyan,movie_type,movie_area,movie_time,movie_jj) VALUES('{$arr_hh['movie_director']}','{$arr_hh['movie_zhuyan']}','{$arr_hh['movie_type']}','{$arr_hh['movie_area']}','{$arr_hh['movie_time']}','{$arr_hh['movie_jj']}')";
//    $dbh->exec($sql);



//}
//预处理
//$dbh=new PDO('mysql:host=localhost;dbname=gaofei','root','root');
//$pre=$dbh->prepare('insert into happy(movie_director,movie_zhuyan) VALUES( ? ,?)');
//$pre->bindParam(1,$movie_director);
//$pre->bindParam(2,$movie_zhuyan);
////开启事务
//$dbh->beginTransaction();
//foreach($arr_tt[1] as $key=>$value)
//{
//    $movie_director=$value;
//    $movie_zhuyan=$arr_tt[2][$key];
//    $query=$pre->execute();
//    if($query==true)
//    {
//        $dbh->commit();
//
//    }
//    else{
//        $dbh->rollBack();
//
//    }
//}
function curl($url)
{
    $ch=curl_init();
    curl_setopt($ch,CURLOPT_HEADER,0);
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);
    curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
    $url=curl_exec($ch);
    return $url;
}
